﻿import { request } from 'umi';

/**
* get one record by id
*/
export async function getRoleSecuredItemById(id: number, params: object = {}) {
    return request<ApiResponse.ResultModel<RoleSecuredItemType.RoleSecuredItemResponse>>(`/roleSecuredItem/getById/${id}`, {
        method: 'GET',
        params: params
    });
}

/**
* get all records
*/
export async function getRoleSecuredItemAll(params: object = {}) {
    return request<ApiResponse.ResultModel<RoleSecuredItemType.RoleSecuredItemResponse>>(`/roleSecuredItem/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* get records by page
*/
export async function getRoleSecuredItemPageList(params: object = {}) {
    return request<PageInfo.PageResponse<RoleSecuredItemType.RoleSecuredItemResponse>>(`/roleSecuredItem/getAll`, {
        method: 'GET',
        params: params
    });
}

/*
* update partial field of record
*/
export async function commonUpdate(id: number, fieldName: string, value: string) {
    return request<PageInfo.PageResponse<RoleSecuredItemType.RoleSecuredItem>>(`/roleSecuredItem/PatchById?id=${id}`, {
        method: 'PATCH',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [{
            "id": id,
            "op": "replace",
            "path": `/${fieldName}`,
            "value": value

        }]
    });
}

/*
* update record
*/
export async function updateRoleSecuredItem(params: RoleSecuredItemType.RoleSecuredItemResponse) {
    return request<ApiResponse.ResultModel<boolean>>(`/roleSecuredItem/put`, {
        method: 'put',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params],
    });
}

/*
* add one record
*/
export async function addRoleSecuredItem(params: RoleSecuredItemType.RoleSecuredItemResponse) {
    return request<ApiResponse.ResultModel<RoleSecuredItemType.RoleSecuredItemResponse>>('/roleSecuredItem/add', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params],
    });
}

export async function deleteRoleSecuredItem(params: DeleteRequest) {
    return request<ApiResponse.ResultModel<boolean>>(`/roleSecuredItem/delete`, {
        method: 'DELETE',
        headers: {
            'Content-Type': 'application/json',
        },
        data: [params.id],
    });
}
